<?php
/**
 *
 * @author Lukas Normantas
 */
class Areal_Image {
    //put your code here


    static public function getThumbContent($original_file)
    {
        if ( ! file_exists($original_file)){
            return file_get_contents(DATA_PATH . 'default_images/no_thumb.jpg');
        }
        $thumbWidth = 100;

        $img = imagecreatefromjpeg($original_file);
        $width = imagesx( $img );
        $height = imagesy( $img );

        // calculate thumbnail size
        $new_width = $thumbWidth;
        $new_height = floor( $height * ( $thumbWidth / $width ) );

        // create a new temporary image
        $tmp_img = imagecreatetruecolor( $new_width, $new_height );

        // copy and resize old image into new image
        imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
        return imagejpeg( $tmp_img);
    }

    static public function getImageContent($original_file)
    {
        if ( ! file_exists($original_file)){
            return file_get_contents(DATA_PATH . 'default_images/no_image.jpg');
        }
        $max_width = 640;
        $max_height = 480;

        $img = imagecreatefromjpeg($original_file);
        $width = imagesx( $img );
        $height = imagesy( $img );

        $max_width_ratio =  $width / $max_width;
        $max_height_ratio =  $height / $max_height;

        $ratio = ($max_width_ratio > $max_height_ratio)?$max_width_ratio:$max_height_ratio;


        $new_width = floor( $width / $ratio );
        $new_height = floor( $height / $ratio);

        // create a new temporary image
        $tmp_img = imagecreatetruecolor( $new_width, $new_height );

        // copy and resize old image into new image
        imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

        return imagejpeg( $tmp_img);
    }





}

